/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uoc.tdp.pac3.persistence.dao;

import edu.uoc.tdp.pac3.domain.User;
import java.util.List;
import edu.uoc.tdp.pac3.persistence.dao.impl.UserDao;
import java.sql.Date;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Gerard
 */
public class UserDaoTestCase {
    
    private static IUserDao dao;
    
    @BeforeClass
    public static void setUpClass() throws Exception {
        dao = new UserDao();
    }
    
    @Test
    public void test_retrieve_data(){
        List<User> list = dao.findAll();
        for(User user : list){
            System.out.println(user.getId());
        }
        assertEquals(5, list.size());
    }
    
    @Test
    public void test_findById(){
        User user = dao.findById(2);
        assertNotNull(user);
    }
    
    @Test
//    @Ignore
    public void test_insert(){
        User user = new User();
        user.setId(6);
        user.setName("JUNIT");
        user.setCreationDate(new Date(2011, 1, 1));
        assertTrue(dao.insert(user));
    }
    
    @Test
    public void test_update(){
        User user = dao.findById(1);
        user.setName("JUNIT");
        assertTrue(dao.update(user));
    }
    
    @Test
//    @Ignore
    public void test_delete(){
        User user = dao.findById(6);
        assertNotNull(user);
        Boolean result = dao.delete(user);
        assertTrue(result);
    }

}
